package day13.problem1;

import java.util.*;

//牛牛冲钻五
//https://ac.nowcoder.com/acm/problem/227309

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        while(t-- > 0) {
            int n = in.nextInt();
            int k = in.nextInt();
            String s = in.next();
            int sum = 0;
            for(int i = 0; i<n; i++) {
                if(s.charAt(i) == 'W') {
                    if(i >= 2 && s.charAt(i-1) == 'W' && s.charAt(i-2) == 'W') {
                        sum += k;
                    }else {
                        sum ++;
                    }
                }else {
                    sum --;
                }
//                 System.out.println(sum);
            }
            System.out.println(sum);
        }
    }
}